using ASP;
using HoWave.Common;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Text;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class HL_Admin_Admin_AddAdminGroup : Admin, IRequiresSessionState
{
	private AdminGroupBll _adminGroup = null;
	private AdminBll _admin = null;
	private int adminGroupId;
	protected TextBox TxtGroupName;
	protected RequiredFieldValidator RequiredFieldValidator1;
	protected ListBox ListUser;
	protected TextBox TxtRemark;
	protected CheckBox CheckAccess;
	protected CheckBox cb_all;
	protected CheckBox cb_MS;
	protected CheckBox cb_Channel;
	protected CheckBox cb_announce;
	protected CheckBox cb_advertisement;
	protected CheckBox cb_conformity;
	protected CheckBox cb_CheckUser;
	protected CheckBox cb_Pass;
	protected CheckBox cb_Group;
	protected CheckBox cb_ShortMessage;
	protected CheckBox cb_Email;
	protected CheckBox cb_ShopArticle;
	protected CheckBox cb_Project;
	protected CheckBox cb_SiteSkin;
	protected CheckBox cb_Team;
	protected CheckBox cb_DefindLable;
	protected CheckBox cb_DeFindPage;
	protected CheckBox cb_SetiSpecial;
	protected CheckBox cb_ShopManage;
	protected CheckBox cb_ShopMessage;
	protected CheckBox cb_ShopRequest;
	protected CheckBox cb_ShopProduct;
	protected CheckBox cb_ShopOrder;
	protected CheckBox cb_ShopSale;
	protected CheckBox cb_ShopReview;
	protected CheckBox cb_Pic;
	protected CheckBox cb_ShopArea;
	protected CheckBox cb_ShopCard;
	protected CheckBox cb_ShopMoney;
	protected CheckBox cb_SitePayType;
	protected CheckBox cb_ShopBank;
	protected CheckBox cb_ShopPayType;
	protected CheckBox cb_ShopDelive;
	protected CheckBox cb_ShopVipUser;
	protected CheckBox cb_ShopVipLevel;
	protected CheckBox cb_ShopSetup;
	protected CheckBox cb_MobileMessage;
	protected CheckBox cb_SubSite;
	protected CheckBox cb_Witkey;
	protected CheckBox cb_vipcardmanage;
	protected CheckBox cb_giftcardmanage;
	protected CheckBox cb_lotterymanage;
	protected CheckBox cb_tryclothesmanage;
	protected CheckBox cb_couponmanage;
	protected CheckBox cb_financemanage;
	protected CheckBox cb_useclientrelation;
	protected CheckBox cb_stockmanage;
	protected CheckBox cb_jxcmanage;
	protected Panel PanelPower;
	protected HtmlTableRow rowpower;
	protected Button ButAdd;
	protected Button ButUpdate;
	protected AdminGroupBll m_adminGroup
	{
		get
		{
			AdminGroupBll adminGroup;
			if (this._adminGroup == null)
			{
				this._adminGroup = new AdminGroupBll(this.conn);
				adminGroup = this._adminGroup;
			}
			else
			{
				adminGroup = this._adminGroup;
			}
			return adminGroup;
		}
	}
	protected AdminBll m_admin
	{
		get
		{
			AdminBll admin;
			if (this._admin == null)
			{
				this._admin = new AdminBll(this.conn);
				admin = this._admin;
			}
			else
			{
				admin = this._admin;
			}
			return admin;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.adminGroupId = Fetch.GetID("AdminGroupID");
		if (!base.admin.CheckSuperAdmin())
		{
			base.WriteLog("View", Language.GetAdminMsg("Log/Access", this.adminGroupId.ToString()), "AdminGroup");
			base.WriteRightErrMsg();
		}
		if (!base.IsPostBack)
		{
			DataTable allAdmin = this.m_admin.GetAllAdmin();
			this.ListUser.DataSource = allAdmin;
			this.ListUser.DataTextField = "UserName";
			this.ListUser.DataValueField = "Admin_ID";
			this.ListUser.DataBind();
			if (this.adminGroupId != 0)
			{
				this.BindBaseDate(this.adminGroupId);
				this.ButUpdate.Visible = true;
				this.ButAdd.Visible = false;
			}
			this.CheckAccess.Attributes.Add("onclick", "return ShowRowPower()");
		}
	}
	protected void BindBaseDate(int AdminGroupID)
	{
		DataTable adminGroupByID = this.m_adminGroup.GetAdminGroupByID(AdminGroupID);
		if (adminGroupByID.Rows.Count > 0)
		{
			DataTable adminByGroupID = this.m_admin.GetAdminByGroupID(AdminGroupID);
			for (int i = 0; i < adminByGroupID.Rows.Count; i++)
			{
				foreach (ListItem listItem in this.ListUser.Items)
				{
					if (listItem.Value.Trim() == adminByGroupID.Rows[i]["Admin_ID"].ToString().Trim())
					{
						listItem.Selected = true;
					}
				}
			}
			string power = adminGroupByID.Rows[0]["Power"].ToString();
			if (adminGroupByID.Rows[0]["Access"].ToString() == "1")
			{
				this.CheckAccess.Checked = true;
			}
			else
			{
				this.CheckAccess.Checked = false;
				this.rowpower.Visible = true;
			}
			this.TxtRemark.Text = adminGroupByID.Rows[0]["Remark"].ToString();
			this.TxtGroupName.Text = adminGroupByID.Rows[0]["AdminGroupName"].ToString();
			this.SetPower(power);
		}
	}
	protected void Button_Command(object sender, CommandEventArgs e)
	{
		int iD = Fetch.GetID("AdminGroupID");
		string power = this.GetPower();
		string text = "";
		foreach (ListItem listItem in this.ListUser.Items)
		{
			if (listItem.Selected)
			{
				text = text + listItem.Value + ",";
			}
		}
		if (text.Length > 1)
		{
			text = text.Remove(text.Length - 1);
		}
		int access = 0;
		if (this.CheckAccess.Checked)
		{
			access = 1;
		}
		if (e.CommandName == "add")
		{
			if (this.m_adminGroup.AddAdminGroup(this.TxtGroupName.Text, access, this.TxtRemark.Text, power, text))
			{
				base.WriteLog("AddNew", Language.GetAdminMsg("Log/ObjectID", "0"), "AdminGroup");
				this.WriteSuccessMsg("", Language.GetAdminMsg("Common/AddSuccess"), "Admin_AdminGroup.aspx");
			}
			else
			{
				this.WriteErrMsg("", Language.GetAdminMsg("Common/AddFail", "未知"), "");
			}
		}
		else
		{
			if (this.m_adminGroup.UpdateGroup(this.TxtGroupName.Text, access, this.TxtRemark.Text, power, iD, text))
			{
				base.WriteLog("Modify", Language.GetAdminMsg("Log/ObjectID", iD.ToString()), "AdminGroup");
				this.WriteSuccessMsg("", Language.GetAdminMsg("Common/EditSuccess"), "Admin_AdminGroup.aspx");
			}
			else
			{
				this.WriteErrMsg("", Language.GetAdminMsg("Common/EditFail", "未知"), "");
			}
		}
	}
	protected string getcb(CheckBox cb)
	{
		string result;
		if (cb.Checked)
		{
			result = "1";
		}
		else
		{
			result = "0";
		}
		return result;
	}
	protected void setcb(CheckBox cb, string val)
	{
		try
		{
			if (val.Trim() == "1")
			{
				cb.Checked = true;
			}
			else
			{
				cb.Checked = false;
			}
		}
		catch
		{
		}
	}
	protected CheckBox[] GetCheckBoxes()
	{
		return new CheckBox[]
		{
			this.cb_MS,
			this.cb_Channel,
			this.cb_announce,
			this.cb_advertisement,
			this.cb_conformity,
			this.cb_CheckUser,
			this.cb_Pass,
			this.cb_Group,
			this.cb_ShortMessage,
			this.cb_Email,
			this.cb_ShopArticle,
			this.cb_Project,
			this.cb_SiteSkin,
			this.cb_Team,
			this.cb_DefindLable,
			this.cb_DeFindPage,
			this.cb_SetiSpecial,
			this.cb_ShopManage,
			this.cb_ShopMessage,
			this.cb_ShopRequest,
			this.cb_ShopProduct,
			this.cb_ShopOrder,
			this.cb_ShopSale,
			this.cb_ShopReview,
			this.cb_Pic,
			this.cb_ShopArea,
			this.cb_ShopCard,
			this.cb_ShopMoney,
			this.cb_SitePayType,
			this.cb_ShopBank,
			this.cb_ShopPayType,
			this.cb_ShopDelive,
			this.cb_ShopVipUser,
			this.cb_ShopVipLevel,
			this.cb_ShopSetup,
			this.cb_MobileMessage,
			this.cb_SubSite,
			this.cb_Witkey,
			this.cb_vipcardmanage,
			this.cb_giftcardmanage,
			this.cb_lotterymanage,
			this.cb_tryclothesmanage,
			this.cb_couponmanage,
			this.cb_financemanage,
			this.cb_useclientrelation,
			this.cb_stockmanage,
			this.cb_jxcmanage
		};
	}
	protected string GetPower()
	{
		StringBuilder stringBuilder = new StringBuilder();
		CheckBox[] checkBoxes = this.GetCheckBoxes();
		int i;
		for (i = 0; i < checkBoxes.Length - 1; i++)
		{
			stringBuilder.Append(this.getcb(checkBoxes[i]) + "|");
		}
		stringBuilder.Append(this.getcb(checkBoxes[i]));
		return stringBuilder.ToString();
	}
	protected void SetPower(string Power)
	{
		string[] array = Power.Split(new char[]
		{
			'|'
		});
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = array[i].Substring(0, 1);
		}
		try
		{
			CheckBox[] checkBoxes = this.GetCheckBoxes();
			for (int i = 0; i < checkBoxes.Length; i++)
			{
				this.setcb(checkBoxes[i], array[i]);
			}
		}
		catch
		{
		}
	}
}
